<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>循环结构</title>
</head>
<body>
  <script>

    for (var i = 0; i < 4; i++) {
      var str = "";
      for (var j = 0; j < 4-i-1; j++) {
         str += " ";
      }
      for (var j = 0; j <= i; j++) {
        str += "*";
      }
      console.log(str)
    }

    for (var i = 0; i <= 4; i++) {
      var str = "";
      for (var j = 0; j < 4-i; j++) {
        str += " ";
      }
      for (var j = 0; j < 2*i-1; j++) {
        str+="*";
      }
      console.log(str)
    }
  </script>
</body>
</html>